// 使用一个队列实现
/**
 * Initialize your data structure here.
 */
var MyStack = function() {
  this.queue = [];
};

/**
* Push element x onto stack. 
* @param {number} x
* @return {void}
*/
MyStack.prototype.push = function(x) {
  this.queue.push(x);
};

/**
* Removes the element on top of the stack and returns that element.
* @return {number}
*/
MyStack.prototype.pop = function() {
  let size = this.queue.length;
  while(size-- > 1) {
      this.queue.push(this.queue.shift());
  }
  return this.queue.shift();
};

/**
* Get the top element.
* @return {number}
*/
MyStack.prototype.top = function() {
  const x = this.pop();
  this.queue.push(x);
  return x;
};
/**
* Returns whether the stack is empty.
* @return {boolean}
*/
MyStack.prototype.empty = function() {
  return !this.queue.length;
};